﻿using RockBus.Composition.Interfaces;
using RockBus.DataContracts;
using RockBus.Hosting.Interfaces;
using RockBus.Logging.Interfaces;
using RockBus.Services;
using RockBus.Transport.Interfaces;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;

namespace RockBus.Hosting.Web
{
    public class DynamicServiceHost : ReceivePortServiceHostBase<CbrService>
    {
        public DynamicServiceHost(ILogger logger, ReceivePortInfo receivePortInfo)
            : base(logger, receivePortInfo.ReceiveEndpointInfo, receivePortInfo.GetPublisherReceivePortInfo())
        {
            this.Logger.LogInfo(MethodBase.GetCurrentMethod(), "Creating DynamicServiceHost on original address {0}", receivePortInfo.ReceiveEndpointInfo.Address);

            this.ReceivePortBaseAddresses = DynamicServiceHelper.BaseAddresses.ToArray();

            this.InitializeDescription(typeof(CbrService), new UriSchemeKeyedCollection());
        }
    }
}